<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Artist_model extends CI_Model
{
	public function __construct()
	{
        parent::__construct();
	}
	
	function get_all($num, $offset, $banner_type='')
	{
		//if($banner_type) $this->db->where('banner_type', $banner_type);
        $this->db->where('(banner_type= "ARTIST" OR banner_type = "MC")');
		$this->db->where('bl_active !=', -1);
		$this->db->order_by('nb_position','ASC');
		$this->db->order_by('nb_order','ASC');
		return $this->db->get('fm_banner',$num,$offset)->result();
	}
	
	function get_num($banner_type='')
	{
		//if($banner_type) $this->db->where('banner_type', $banner_type);
        $this->db->where('(banner_type= "ARTIST" OR banner_type = "MC")');
		$this->db->where('bl_active !=', -1);
		return $this->db->get('fm_banner')->num_rows();          
	}
	
	function del($id)
	{
		$data['bl_active'] = -1 ;
		$data['dt_modify'] = date("Y-m-d H:i:s") ;
		$this->db->where('banner_id',$id);
		if($this->db->update('fm_banner', $data)){
		  	return true;
		}else{
		  	return false;
		}
	}
	
	function remove()
	{
		$date = new DateTime();
		$date->modify('-3 month');
		$date_del = $date->format('Y-m-d H:i:s');
		
		$this->db->where('bl_active', -1);
		$this->db->where('dt_modify <', $date_del);
		if($this->db->delete('fm_banner')){
		  	return true;
		}else{
		  	return false;
		}
	}
	
	function save($data, $id=0)
	{
		 if($id){
			  $this->db->where('banner_id',$id);
			  if($this->db->update('fm_banner',$data)){
					return true;
			  }else{
					return false;
			  }
		 }else{
			  if($this->db->insert('fm_banner',$data)){
					return true;
			  }else{
					return false;
			  }
		 }          
	}
	
	function get_id($id=0)
	{
		 $this->db->where('banner_id',$id);
		 return $this->db->get('fm_banner')->row();
	}
	
	function get_list_country()
	{
		 $this->db->order_by('lb_country','ASC');
		 return $this->db->get('fm_country')->result();
	}
}
